A web content management server is a server that optimizes web pages and web page interactions for client devices with special requirements, such as smartphones. By way of example, a client device can send an HTTP request for a web page which is retrieved from a server device by the web content management server. Next, the web content management server can optimize the content of the web page by applying transformation rules tailored to the requesting client device. This optimization process can include extracting content relevant to the requesting client device and adapting the extracted content to fit the specifications of the requesting client device. In order to adapt the content, the web content management server can perform transformations including JavaScript removal, content linearization, and small screen adaptation, for example.
Although this process works well to optimize content for display at the requesting client device, the web page may not function properly when the original content heavily depends on JavaScript technology that cannot be implemented on some client devices. For example, if the requested web page includes JavaScript code responsible for populating form fields, validating form submissions, retrieving data from external resources (e.g., based on AJAX technology), and even generating components that may change the structure of the web page, the page at the client device will not be able to properly function.
Accordingly, JavaScript included in web pages can be removed, stored by the web content management server, and replaced by a hidden field with an identifier, for example. The identifier is subsequently sent by the client device in an HTTP request in response to a web page interaction requiring execution of the JavaScript, such as a request for validation of login credentials. Based on the identifier, the web content management server can retrieve the JavaScript, execute the JavaScript in an emulated JavaScript environment on behalf of the client device, and return a result to the client device.
In some implementations, the emulated JavaScript environment can support application programming interfaces (APIs) such as those defined by hypertext markup language (HTML), events, cascading style sheet (CSS), range, traversal, and views models, for example. Some of the supported APIs can allow web page developers to embed JavaScript defining functionality for accessing a document object model (DOM) associated with a web page in order to perform an operation. For example, the selector API provides CSS selector expressions or queries configured to be applied to a DOM to obtain a result set of elements of the DOM.
However, CSS selector expressions can be difficult to implement, can be complex, and can require specific code or libraries to be implemented. While some CSS selector expressions can be translated into XML path language (XPath) expressions or queries, which are relatively efficient to execute, many CSS selector expressions are not translatable.